import java.lang.reflect.Array;

public class Test {
    public static int removeElement(int[] nums, int val) {
        int i=0;
        int j=nums.length-1;
        int len = j;
        while(i<j){
            while(i<j&&nums[i]!=val){
                i++;
            }
            while(i<j&&nums[j]==val){
                j--;
            }
            if(i<j) {
                swap(nums,i,j);
                len--;
            }
        }
        for(int k=0;k<nums.length;k++) {
            System.out.print(nums[k]+" ");
        }
        return len;
    }
    static  public void swap(int[]nums,int a,int b) {
        System.out.println(a+" "+b);
        int tmp = nums[a];
        nums[a]=nums[b];
        nums[b]=tmp;
    }

    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        int len = removeElement(nums,3);
        System.out.println(nums.toString());
    }
}
